<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.3.0: http://docutils.sourceforge.net/" />
<title>Command Line Usage</title>
<link rel="stylesheet" href="default.css" type="text/css" />
</head>
<body>
<div class="document" id="command-line-usage">
<h1 class="title">Command Line Usage</h1>
<!-- filename: c:\development\python22\lib\site-packages\vb2py\doc/commandline.htm -->
<p>The easiest way to use vb2Py from the command line is by working in the vb2py directory in your Python site-packages location.</p>
<p>To check the basic usage from the command line:</p>
<pre class="literal-block">
&gt; python converter.py -h
</pre>
<p>Two example projects should be installed in the folder, <tt class="literal"><span class="pre">vb2py/vb/test1</span></tt> and <tt class="literal"><span class="pre">test2</span></tt>. To convert the <tt class="literal"><span class="pre">test2</span></tt> project (which is slightly more meaningful than <tt class="literal"><span class="pre">test1</span></tt>!) to a PythonCard project, use the command:</p>
<pre class="literal-block">
&gt; python converter.py -c vb/test/test2.vbp vb/test/test2

-c = convert the code also      
vb/test/test2.vbp = the VB project file for the project 
vb/test/test2 = the location of the generated Python files
</pre>
<p>The directory where the Python files will be put <strong>must</strong> exist before you run the conversion.</p>
<p>If you have <a class="reference" href="intallation.htm#pythoncard-installation">PythonCard</a> installed you can see what the forms look like by typing:</p>
<pre class="literal-block">
&gt; python vb/test/test2/frmMain.py
</pre>
<p>You should see a form open with a lot of controls on it. Clicking on the controls should perform the same actions as for the VB version.</p>
<p><img alt="images/sm_test2_frmmain_py.gif" src="images/sm_test2_frmmain_py.gif" /></p>
<p>See the <a class="reference" href="images/test2_frmmain_py.gif">full form</a></p>
<p>For cases where you don't have a VB project file (<tt class="literal"><span class="pre">*.vbp</span></tt>), you can still use the converter to convert individual files on at a time. The following command will convert the single code module in the test2 project:</p>
<pre class="literal-block">
&gt; python converter.py -c -f vb/test/Utils.bas vb/test/test2
</pre>
<p>The code will be placed in the destination directory. Note that when doing file-by-file conversions certain parts of the conversion will not be possible. In particular, global variables will not be correctly handled since in order to determine the correct qualified name for a global, vb2Py needs to know all the files within the project.</p>
<p>For example, when converting an entire project the following code segment (where <tt class="literal"><span class="pre">BASEDIR</span></tt> is defined in a module called <tt class="literal"><span class="pre">FileGlobals</span></tt>):</p>
<pre class="literal-block">
Function addBaseDirectory(Path as String)
        addBaseDirectory = BASEDIR &amp; Path ' BASEDIR is a global
End Function
</pre>
<p>Would be converted to:</p>
<pre class="literal-block">
def addBaseDirectory(Path):
        _ret = FileGlobals.BASEDIR + Path
        return _ret
</pre>
<p>However, if the file is translated on its own (using the <tt class="literal"><span class="pre">-f</span></tt> command line switch) then it would be converted to:</p>
<pre class="literal-block">
def addBaseDirectory(Path):
        _ret = BASEDIR + Path
        return _ret
</pre>
</div>
</body>
</html>
